﻿using System;
using System.Collections.Generic;
using System.Data;
using Loki.Data;
using Luna.Data.Mappers;

namespace Luna.Data.Accounting.Mappers
{
    public class CreditCardDataMapper : LunaEntityMapper<AccountCreditCardData, IAccountCreditCardData>
    {
        private const string ACCOUNT_ID = "AccountID";
        private const string NUMBER = "Number";
        private const string SECURITY = "Security";
        private const string TYPE = "Type";
        private const string USER_NAME = "UserName";
        private const string VALIDITY = "Validity";

        public string GetAllByAccountRequest { get; set; }

        protected override void LoadCoreData(IAccountCreditCardData P_Entity, IDataRecord P_Record)
        {
            P_Entity.AccountID = P_Record.GetGuid(ACCOUNT_ID);
            P_Entity.Number = P_Record.GetString(NUMBER);
            P_Entity.Security = P_Record.GetString(SECURITY);
            P_Entity.Type = P_Record.GetString(TYPE);
            P_Entity.UserName = P_Record.GetString(USER_NAME);
            P_Entity.Validity = P_Record.GetDate(VALIDITY);
        }

        protected override void MapSaveParameters(IDatabaseCommand P_Command, IAccountCreditCardData P_Entity)
        {
            P_Command.AddParameter(ACCOUNT_ID, P_Entity.AccountID);
            P_Command.AddParameter(TYPE, P_Entity.Type);
            P_Command.AddParameter(USER_NAME, P_Entity.UserName);
            P_Command.AddParameter(NUMBER, P_Entity.Number);
            P_Command.AddParameter(VALIDITY, P_Entity.Validity);
            P_Command.AddParameter(SECURITY, P_Entity.Security);
            P_Command.AddParameter(IDParameterName, P_Entity.PK);
        }

        public IEnumerable<IAccountCreditCardData> GetAllByAccount(IDbTransaction P_Transaction, Guid P_AccountID)
        {
            return ExecuteGetAll(P_Transaction, GetAllByAccountRequest, c => c.AddParameter(ACCOUNT_ID, P_AccountID));
        }
    }
}
